package cn.faster.common.event;

import cn.faster.sys.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author xiaoCoder
 * @version 1.0
 * @description: TODO
 * @date 2021/8/7 13:37
 */
@Component
@Slf4j
public class UserMonitor {

    @Async("lazyTraceExecutor")
    @EventListener(value = UserActionEvent.class,condition = "#event.operate.name()=='LOGOUT'")
    public UserActionEvent addUserApplicationEvent(UserActionEvent event){
        try {
            SysUser sysUser = event.getSysUser();
            log.info("监听到的用户：{}", sysUser);
            log.info("自定义处理：{}","关闭当前用户所属的线程信息！！！"); // 进行自定义处理
        } catch (Exception e) {
            log.error("事件：{}，执行异常：{}",event,e.getMessage());
            return event;
        }
        return null;
    }
}
